layui.config({
    base: $config.resUrl+'other/layui_packge_js/'//定义基目录
}).extend({
    ajaxExtention:'ajaxExtention',//加载自定义扩展，每个业务js都需要加载这个ajax扩展
    $tool:'tool',
    $api:'api'
}).use(['form','layer','laydate','ajaxExtention','$tool','$api'], function() {
	var $ = layui.jquery, 
	laydate = layui.laydate,
	dtree = layui.dtree,
	form = layui.form,
	layer = layui.layer,
	$tool = layui.$tool,
    $api = layui.$api;
	
	//日期控件
	laydate.render({
		elem : '#createTime'
	});
	laydate.render({
		elem : '#updateTime'
	});
	
  //监听提交按钮
	form.on('submit(menuAddSubmit)', function(data){
	  $api.MenuSave(data.field,function (result) {
		  layer.msg(result.msg,{time: 3000},function(){
    		  parent.location.reload();
    	  });
    	  parent.location.reload();
      },function (result) {
    	  layer.msg(JSON.stringify(result));
      });
    return false;
  });
  
  //机构弹出框
  $("#parentName").click(function(){
	  layer.open({
	    type: 1,
	    title: "菜单列表",
	    area: ["350px", "80%"],
	    content: '<ul id="inMenuTree" class="dtree" data-id="0"></ul>',
	    btn: ['确认选择'],
	    success: function(layero, index){
	      dtree.render({
	        elem: "#inMenuTree",
	        url: "/sys/menu/tree.json",
	        dot: false
	      });
	      
	      // 绑定节点的双击
	      dtree.on("nodedblclick('inMenuTree')", function(obj){
	    	$("[name=level]").val(obj.param.level);
	        $("[name=parentId]").val(obj.param.nodeId);
	        $("[name=parentName]").val(obj.param.context);
	        layer.close(index);
	      });
	    },
	    yes: function(index, layero) {
	      var param = dtree.getNowParam("inMenuTree"); // 获取当前选中节点
	      $("[name=level]").val(param.level);
	      $("[name=parentId]").val(param.nodeId);
	      $("[name=parentName]").val(param.context);
	      layer.close(index);
	    }
	  });
	});
});
